using System.Collections;
using Photon;
using UnityEngine;
using UnityEngine.UI;

public class PlayerHealth : Photon.MonoBehaviour
{
	public float m_maxHP;

	public float m_currentHP;

	public float m_regenHP = 20f;

	public Camera m_CameraDead;

	private bool m_Damaged;

	public bool m_Dead;

	private Animator anim;

	private PlayerSetup s_PlayerSetup;

	public Image m_ImageBloodEffect;

	public bool m_Regen;

	private float Timer;

	private float da = 255f;

	private CapsuleCollider m_CapsuleCollider;

	public GameObject BloodEffect;

	private void Awake()
	{
		m_CapsuleCollider = GetComponent<CapsuleCollider>();
		s_PlayerSetup = GetComponent<PlayerSetup>();
	}

	private void Start()
	{
		anim = s_PlayerSetup.anim;
		if (PhotonNetwork.room != null && !PhotonNetwork.offlineMode)
		{
			if (base.photonView.isMine)
			{
				m_currentHP = m_maxHP;
			}
		}
		else
		{
			m_currentHP = m_maxHP;
		}
		if (s_PlayerSetup.admin)
		{
			m_currentHP = 1E+14f;
		}
	}

	private void Update()
	{
	}

	[PunRPC]
	public void TakeDamage(float amount, Vector3 blood_point)
	{
		if (m_currentHP > 0f && !m_Dead)
		{
			GameObject obj = Object.Instantiate(BloodEffect, blood_point, base.transform.rotation) as GameObject;
			Object.Destroy(obj, 3f);
		}
		m_currentHP -= amount;
		if (m_currentHP <= 0f && !m_Dead)
		{
			OnDeath();
		}
	}

	private IEnumerator StartRegen()
	{
		yield return new WaitForSeconds(7f);
		m_Regen = true;
	}

	private void OnDeath()
	{
		m_Dead = true;
		m_CapsuleCollider.enabled = false;
		if (PhotonNetwork.room == null || PhotonNetwork.offlineMode || base.photonView.isMine)
		{
			s_PlayerSetup.s_RigidibodyFPSController.enabled = false;
			s_PlayerSetup.s_RigidibodyFPSController.cam.transform.localRotation = Quaternion.identity;
			s_PlayerSetup.m_Rigidbody.isKinematic = true;
			Cursor.lockState = CursorLockMode.None;
			Cursor.visible = true;
			int value = Random.Range(1, 2);
			s_PlayerSetup.m_Camera.enabled = false;
			m_CameraDead.enabled = true;
			anim.SetInteger("WeaponType_int", 0);
			anim.SetInteger("DeathType_int", value);
			anim.SetBool("Death_b", true);
			s_PlayerSetup.Dead();
		}
	}

	public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
	{
		if (stream.isWriting)
		{
			stream.SendNext(m_currentHP);
			stream.SendNext(m_Dead);
			return;
		}
		float currentHP = m_currentHP;
		m_currentHP = (float)stream.ReceiveNext();
		m_Dead = (bool)stream.ReceiveNext();
		if (m_currentHP != currentHP)
		{
		}
		SetOther();
	}

	private void SetOther()
	{
		if (m_Dead)
		{
			m_CapsuleCollider.enabled = false;
		}
		else if (!m_Dead)
		{
			m_CapsuleCollider.enabled = true;
		}
	}
}
